




***Gettin ubigeos of endes

forvalues i=2010/2019 {
	import spss using "${endesData}/endes`i'/RECH0.SAV", clear
	keep HHID HV024
	gen year=`i'
	save "${endesData}/endes`i'/RECH0.dta", replace

}


forvalues i=2011/2019 {
	import spss using "${endesData}/endes`i'/RECH23.SAV", clear
	keep HHID SHDISTRI SHPROVIN
	gen year=`i'
	save "${endesData}/endes`i'/RECH23.dta", replace

}


forvalues i=2011/2019 {
	use "${endesData}/endes`i'/RECH0.dta", replace
	keep HHID HV024 year
	merge 1:1 HHID using "${endesData}/endes`i'/RECH23.dta", keepusing(SHDISTRI SHPROVIN)

	br HV024 SHDISTRI SHPROVIN
	gen dpto=HV024
	drop HV024

	foreach var of varlist dpto SHDISTRI SHPROVIN {
		tostring `var', replace
		replace `var'= "0" + `var' if length(`var')==1
	}

	gen ubigeo=dpto+SHPROVIN+ SHDISTRI
	keep HHID ubigeo year
	replace HHID = strtrim(HHID) 

	tempfile a`i'
	save `a`i''

}

use "`a2011'", clear
forvalues i=2012/2019 {
	append using `a`i''
}



save "$data_folder/endes_ubigeos.dta", replace

